package com.lufei.dh.bottom.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lufei.dh.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 版权：易金卡沃 版权所有
 * <p>
 * 作者：lufei
 * <p>
 * 创建日期：2018/6/25
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
public class Fragment6 extends Fragment {

    Unbinder unbinder;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    @BindView(R.id.main_content)
    CoordinatorLayout mainContent;



    List<Fragment> mFragments;

    String[] Titles = new String[]{
            "主页", "微博", "相册"
    };

    private List<String> mTitles;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment6, container, false);
        unbinder = ButterKnife.bind(this, view);
        init();
        return view;
    }

    private void init() {
        mTitles=new ArrayList<>();
        Fragment fragment1=new Fragment1();
//        Fragment fragment3=new Fragment3();
        Fragment_Mine mine=new Fragment_Mine();
        for (int i = 0; i < 2; i++) {
            mTitles.add(Titles[i]);
        }
        mFragments = new ArrayList<>();
        mFragments.add(fragment1);
        mFragments.add(mine);
//        for (int i = 0; i < mTitles.length; i++) {
//            ListFragment listFragment = ListFragment.newInstance(mTitles[i]);
//            mFragments.add(listFragment);
//        }
        // 第二步：为ViewPager设置适配器
        BaseFragmentAdapter adapter =
                new BaseFragmentAdapter(getActivity().getSupportFragmentManager(), mTitles,mFragments);

        viewpager.setAdapter(adapter);
        //  第三步：将ViewPager与TableLayout 绑定在一起
        tabs.setupWithViewPager(viewpager);

    }

    public class BaseFragmentAdapter extends FragmentStatePagerAdapter {
        private List<String> mDatas;
        private List<Fragment> mFragments;

        public BaseFragmentAdapter(FragmentManager fm, List<String> mDatas, List<Fragment> fragments) {
            super(fm);
            this.mDatas = mDatas;
            this.mFragments = fragments;
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mDatas.size()==mFragments.size()?mFragments.size():0;
        }

        /**
         * 重写此方法，返回TabLayout的内容
         */
        @Override
        public CharSequence getPageTitle(int position) {//220.194.106.92
            return mDatas.get(position);
        }
    }
    /**
     * 192.168.1.1
     192.168.1.43
     192.168.1.52
     192.168.1.59
     192.168.1.76
     192.168.1.99
     192.168.1.113
     192.168.1.140
     192.168.1.255
     224.0.0.2
     224.0.0.22
     224.0.0.251
     224.0.0.252
     239.11.20.1
     239.255.255.250
     255.255.255.255
     */
}
